package com.example.demo.service.impl;

import com.example.demo.mapper.BaseMapper;
import com.example.demo.service.IService;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * 基础实现类
 * @param <T>
 */
public abstract class BaseService<T> implements IService<T> {

    @Autowired
    protected BaseMapper<T> mapper;

    public Mapper<T> getMapper() {
        return mapper;
    }

    public T selectByKey(Object key) {
        return mapper.selectByPrimaryKey(key);
    }

    public int save(T entity) {
        return mapper.insertSelective(entity);
    }

    public int delete(Object key) {
        return mapper.deleteByPrimaryKey(key);
    }

    public int updateAll(T entity) {
        return mapper.updateByPrimaryKey(entity);
    }

    public int updateNotNull(T entity) {
        return mapper.updateByPrimaryKeySelective(entity);
    }


    public T selectByCond(T entity){
        return mapper.selectOne(entity);
    }

    public List<T> selectAll(T entity) {
        return mapper.select(entity);
    }


    public int selectCount(T entity) {
        return mapper.selectCount(entity);
    }
}
